# Misc. post-build tasks
# $Id: post-build.py 16 2012-01-28 13:10:08Z masroore@gmail.com $

from os import path, getcwd
from shutil import copyfile
from glob import glob

BUILD = "Debug"
#BUILD = "Release"


ASM_EXTENSIONS = ['dll', 'pdb']

ASM_COPY = {
    '1':
        (
            'ReportGeneratorRich',  # IN: folder
            'ReportGeneratorRich',  # IN: filename
            'reports'               # OUT: folder
        ),    
    '2': 
        (
            'ReportGeneratorPlainText',
            'ReportGeneratorPlainText',
            'reports'
        ),   
    '3': 
        (
            'Db4oCatalog',
            'Db4oCatalog',
            'database'
        )
}

LIBS_COPY = {
    'x': 
        (
            'db4*.dll',
            'database'
        ),
    'y':
        (
            'sti*.dll',
            'reports'
        )
}

def get_bin_dir(folder):
    return path.join(getcwd(), path.join(folder, path.join('bin', BUILD)))

extensions_dir = path.join(get_bin_dir('LWEditor'), 'extensions')

for foo, paths in ASM_COPY.items():
    in_folder = get_bin_dir(paths[0])
    out_folder = path.join(extensions_dir, paths[2])
    for fname in ['{}.{}'.format(paths[1], x) for x in ASM_EXTENSIONS]:
        copyfile(path.join(in_folder, fname), path.join(out_folder, fname))

for foo, paths in LIBS_COPY.items():
    pattern = path.join(path.join(getcwd(), 'Libs'), paths[0])
    for match in glob(pattern):
        copyfile(match, path.join(path.join(extensions_dir, paths[1]), path.basename(match)))
        
for match in glob(path.join(path.join(getcwd(), 'Reports'), '*.*')):
    copyfile(match, path.join(path.join(extensions_dir, 'reports'), path.basename(match)))
        
for match in glob(path.join(path.join(getcwd(), 'Assets'), '*.*')):
    copyfile(match, path.join(get_bin_dir('LWEditor'), path.basename(match)))